/*******************************
* generate_instruments.do     *
******************************/
#delimit;
sort stu_id;


gen sa_read_fun = 0;
replace sa_read_fun = 1 if bys87b == 1;
replace sa_read_fun = . if bys87b < 0;

gen a_read_fun = 0;
replace a_read_fun = 1 if bys87b == 2;
replace a_read_fun = . if bys87b < 0;

gen d_read_fun = 0;
replace d_read_fun = 1 if bys87b == 3;
replace d_read_fun = . if bys87b < 0;

gen sd_read_fun = 0;
replace sd_read_fun = 1 if bys87b == 4;
replace sd_read_fun = . if bys87b < 0;

gen sa_math_fun = 0;
replace sa_math_fun = 1 if bys87c == 1;
replace sa_math_fun = . if bys87c < 0;

gen a_math_fun = 0;
replace a_math_fun = 1 if bys87c == 2;
replace a_math_fun = . if bys87c < 0;

gen d_math_fun = 0;
replace d_math_fun = 1 if bys87c == 3;
replace d_math_fun = . if bys87c < 0;

gen sd_math_fun = 0;
replace sd_math_fun = 1 if bys87c == 4;
replace sd_math_fun = . if bys87c < 0;

gen never_attentive_eng = 0 if byte16>=0;
replace never_attentive_eng = 1 if byte16 == 1;
gen never_attentive_math = 0 if bytm16>=0;
replace never_attentive_math = 1 if bytm16 == 1;
*replace never_attentive = . if (byte16 < 0 | bytm16 < 0);

gen rarely_attentive_eng = 0 if byte16>=0;
gen rarely_attentive_math = 0 if bytm16>=0;
gen some_attentive_eng = 0 if byte16>=0;
gen some_attentive_math = 0 if bytm16>=0;
gen mostly_attentive_eng = 0 if byte16>=0;
gen mostly_attentive_math = 0 if bytm16>=0;
gen always_attentive_eng = 0 if byte16>=0;
gen always_attentive_math = 0 if bytm16>=0;

replace rarely_attentive_eng = 1 if byte16 == 2;
replace rarely_attentive_math = 1 if bytm16 == 2;

replace some_attentive_eng = 1 if byte16 == 3;
replace some_attentive_math = 1 if bytm16 == 3;

replace mostly_attentive_eng = 1 if byte16 == 4;
replace mostly_attentive_math = 1 if bytm16 == 4;

replace always_attentive_eng = 1 if byte16 == 5;
replace always_attentive_math = 1 if bytm16 == 5;


gen passive_eng = byte06 if byte06>=0;
gen passive_math = bytm06 if bytm06>=0;

gen talks_outclass_eng = byte07 if byte07>=0;
gen talks_outclass_math = bytm07 if bytm07>=0;


foreach var in never_attentive some_attentive mostly_attentive rarely_attentive  passive talks_outclass {;
gen `var'_dif_abs = abs(`var'_eng-`var'_math);
};
gen sa_fun_dif_abs = abs(sa_read_fun-sa_math_fun);
gen a_fun_dif_abs = abs(a_read_fun-a_math_fun);
gen d_fun_dif_abs = abs(d_read_fun-d_math_fun);


label var tchavg_col_mb "Teacher's average expectations (Math)";
label var tchavg_col_eb "Teacher's average expectations (ELA)";

label var passive_eng "Passive (ELA)";
label var passive_math "Passive (Math)";
label var never_attentive_eng "Never attentive (ELA)";
label var never_attentive_math "Never attentive (Math)";
label var rarely_attentive_eng "Rarely attentive (ELA)";
label var some_attentive_eng "Sometimes attentive (ELA)";
label var mostly_attentive_eng "Mostly attentive (ELA)";
label var rarely_attentive_math "Rarely attentive (Math)";
label var some_attentive_math "Sometimes attentive (Math)";
label var mostly_attentive_math "Mostly attentive (Math)";
label var sa_read_fun "Strongly agree reading is fun";
label var a_read_fun "Agree reading is fun";
label var d_read_fun "Disagree reading is fun";
label var sa_math_fun "Strongly agree math is fun";
label var a_math_fun "Agree math is fun";
label var d_math_fun "Disagree math is fun";
